// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.

#[allow(unused_imports)]
use super::*;

#[doc(hidden)]
impl serde::ser::Serialize for super::TestStatus {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !self.name.is_empty() {
            state.serialize_entry("name", &self.name)?;
        }
        if !self.failure_message.is_empty() {
            state.serialize_entry("failureMessage", &self.failure_message)?;
        }
        if !self.matched_name.is_empty() {
            state.serialize_entry("matchedName", &self.matched_name)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::FailureSet {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !self.test.is_empty() {
            state.serialize_entry("test", &self.test)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::ConformanceRequest {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if let Some(value) = self.protobuf_payload() {
            struct __With<'a>(&'a ::bytes::Bytes);
            impl<'a> serde::ser::Serialize for __With<'a> {
                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
                where
                    S: serde::ser::Serializer,
                {
                    serde_with::As::<serde_with::base64::Base64>::serialize(self.0, serializer)
                }
            }
            state.serialize_entry("protobufPayload", &__With(value))?;
        }
        if let Some(value) = self.json_payload() {
            state.serialize_entry("jsonPayload", value)?;
        }
        if let Some(value) = self.jspb_payload() {
            state.serialize_entry("jspbPayload", value)?;
        }
        if let Some(value) = self.text_payload() {
            state.serialize_entry("textPayload", value)?;
        }
        if !wkt::internal::is_default(&self.requested_output_format) {
            state.serialize_entry("requestedOutputFormat", &self.requested_output_format)?;
        }
        if !self.message_type.is_empty() {
            state.serialize_entry("messageType", &self.message_type)?;
        }
        if !wkt::internal::is_default(&self.test_category) {
            state.serialize_entry("testCategory", &self.test_category)?;
        }
        if self.jspb_encoding_options.is_some() {
            state.serialize_entry("jspbEncodingOptions", &self.jspb_encoding_options)?;
        }
        if !wkt::internal::is_default(&self.print_unknown_fields) {
            state.serialize_entry("printUnknownFields", &self.print_unknown_fields)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::ConformanceResponse {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if let Some(value) = self.parse_error() {
            state.serialize_entry("parseError", value)?;
        }
        if let Some(value) = self.serialize_error() {
            state.serialize_entry("serializeError", value)?;
        }
        if let Some(value) = self.timeout_error() {
            state.serialize_entry("timeoutError", value)?;
        }
        if let Some(value) = self.runtime_error() {
            state.serialize_entry("runtimeError", value)?;
        }
        if let Some(value) = self.protobuf_payload() {
            struct __With<'a>(&'a ::bytes::Bytes);
            impl<'a> serde::ser::Serialize for __With<'a> {
                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
                where
                    S: serde::ser::Serializer,
                {
                    serde_with::As::<serde_with::base64::Base64>::serialize(self.0, serializer)
                }
            }
            state.serialize_entry("protobufPayload", &__With(value))?;
        }
        if let Some(value) = self.json_payload() {
            state.serialize_entry("jsonPayload", value)?;
        }
        if let Some(value) = self.skipped() {
            state.serialize_entry("skipped", value)?;
        }
        if let Some(value) = self.jspb_payload() {
            state.serialize_entry("jspbPayload", value)?;
        }
        if let Some(value) = self.text_payload() {
            state.serialize_entry("textPayload", value)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::JspbEncodingConfig {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !wkt::internal::is_default(&self.use_jspb_array_any_format) {
            state.serialize_entry("useJspbArrayAnyFormat", &self.use_jspb_array_any_format)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}
